#pragma once

#include <algorithm>
#include <cstdint>
#include <cstring>

namespace limbo {

struct Chunk {
  Chunk() = default;
  Chunk(void *data, uint32_t size) : data_{data}, size_{size} {}
  Chunk(Chunk &&) = default;
  Chunk(const Chunk &) = default;
  Chunk &operator=(const Chunk &) = default;

  unsigned char *data() { return static_cast<unsigned char *>(data_); }

  const unsigned char *data() const {
    return static_cast<const unsigned char *>(data_);
  }

  uint32_t size() const { return size_; }

  Chunk skip(int32_t prefix) {
    auto value = std::min(prefix, static_cast<int32_t>(size_));
    auto ptr = static_cast<char *>(data_);
    return {ptr + value, size_ - value};
  }

  void *data_;
  uint32_t size_ = 0;
};

} // namespace limbo
